<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/1/8
 * Time: 11:37
 */
base::load_class('memcache_d');
base::load_class('model');
class content_model extends model{
    private $m;
    public function __construct(){
        $this->config = base::load_config('database');
        $this->table = 'article';
        $this->seting = 'default';
        $m_config = base::load_config('memcached');
        $this->m = new memcache_d($m_config,$this->table);
        parent::__construct();
    }

    /**
     * @param string $data
     * @param string $where
     * @param string $order
     * @param string $limit
     * @param string $group
     * @return array|bool|mixed|mysqli_result
     */
    public function selectCached($data='*',$where='',$order='',$limit='',$group=''){
        $keydata = $data =='*'?'*':implode($data);
        $key = $keydata.$this->table.$where.$order.$limit.$group;
        $rs = $this->m->get($key);
        if(!$rs){
           $rs = $this->select($data,$where,$order,$limit,$group);
            $this->m->add($key,$rs);
            return $rs;
        }
        return $rs;
    }

    /**
     * @param $data
     * @return array|bool|mysqli_result
     */
    public function insertCached($data){
        $bool = $this->insert($data);
        if($bool){
            $this->m->flush();
        }
        return $bool;
    }

}